package geektime.jdk.classanalyze;

import geektime.jdk.classanalyze.inter.CodingProcess;
import geektime.jdk.classanalyze.inter.Mood;

import java.time.LocalDateTime;

public class ClassFileAnalysis extends ClassFile implements CodingProcess {

    private String name;

    private Mood mood;

    public ClassFileAnalysis(String name, Mood mood) {
        this.name = name;
        this.mood = mood;
    }

    public static void main(String[] args) {
        new ClassFileAnalysis("Zero", new HappyMood()).coding("Java");
        System.out.println(getSum(10, 3));
        System.out.println(getSum(10L, 3L));
        System.out.println(getSum(10.3F, 3.5F));
        System.out.println(getSum(10.33D, 3.68D));
        System.out.println(getSum("s", 3.68D));
    }

    public static <T> T getSum(T a, T b) {
        if (a instanceof Integer && b instanceof Integer) {
            return (T) Integer.valueOf((Integer) a + (Integer) b);
        } else if (a instanceof Long && b instanceof Long) {
            return (T) Long.valueOf((Long) a + (Long) b);
        } else if (a instanceof Float && b instanceof Float) {
            return (T) Float.valueOf((Float) a + (Float) b);
        } else if (a instanceof Double && b instanceof Double) {
            return (T) Double.valueOf((Double) a + (Double) b);
        } else {
            throw new RuntimeException("The parameter type " + a.getClass() + " is unsupported!");
        }
    }

    @Override
    public void coding(String lang) {
        System.out.println(name + "is coding by " + lang + " at " + localDateTimeToString(LocalDateTime.now()));
    }
}
